export default class Scanner {
    constructor(templateStr) {
        this.pos = 0;
        this.templateStr = templateStr;
        this.tail = templateStr;
    }

    scan(stopTag) {
        const omitLen = stopTag.length;

        this.pos += omitLen;
        this.tail = this.tail.substring(omitLen);
    }

    scanUtil(stopTag) {
        const index = this.tail.indexOf(stopTag);
        const pos_backup = this.pos;

        this.pos += index === -1
            ? this.tail.length
            : index;

        this.tail = this.templateStr.substring(this.pos);

        return this.templateStr.substring(pos_backup, this.pos);
    }

    eos() {
        return this.pos < this.templateStr.length;
    }
}